package com.heima.article.task;

import com.heima.article.service.IApArticleService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class HotArticleTask {

    @Autowired
    private IApArticleService apArticleService;

    // @Scheduled(cron = "0 0 1 * * ?") // 每天凌晨一点执行
    // @Scheduled(cron = "0/30 * * * * ?") // 模拟
    @XxlJob("computeHotArticleJob")
    public ReturnT<String> computeHotArticleJob(String param){
        log.info("[文章微服务======>热点文章定时查询任务开启]");
        try {
            apArticleService.compute();
        } catch (Exception e) {
            e.printStackTrace();
            return ReturnT.FAIL;
        }
        return ReturnT.SUCCESS;
    }
}
